package com.cloudbroker.bcs.platform.ltb.common.marketUtil.controller;

import com.cloudbroker.bcs.platform.ltb.common.marketUtil.bean.AccessToken;
import com.cloudbroker.bcs.platform.ltb.common.marketUtil.util.HttpClientUtil;
import com.cloudbroker.bcs.platform.ltb.common.marketUtil.util.JacksonUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 行情 
 * @author luopeng12856
 * 2016—05-26
 */
public class MarketController {
	private static String APPKEY    = "36925ca9-6768-47f7-8124-fa2a9a8a2c7d";
	private static String APPSECRET = "d392dff7-14f5-4437-a0b2-5386fa72162f";
	private static String BASIC     = "Basic ";

	public static void main(String[] args) throws IOException {

		// 客户端凭证模式 获取令牌
		Map<String, String> token_map = new HashMap<String, String>();
		token_map.put("grant_type", "client_credentials");// 客户端凭证模式时，必须为“client_credentials”；
		String tokenResult = HttpClientUtil.sendPost(HttpClientUtil.URL + "/oauth2/oauth2/token", token_map,
				HttpClientUtil.CHARSET, HttpClientUtil.CHARSET, null, HttpClientUtil.Base64(APPKEY, APPSECRET, BASIC),
				"获取公共令牌");
		// 解析返回数据json
		AccessToken accesstoken = JacksonUtils.json2Object(tokenResult, AccessToken.class);
		Map<String, String> market_list_map = new HashMap<String, String>();
		HttpClientUtil.sendPost(HttpClientUtil.URL + "/quote/v1/market/list", market_list_map, HttpClientUtil.CHARSET,
				HttpClientUtil.CHARSET, null, HttpClientUtil.BEARER + accesstoken.getAccess_token(), "市场列表目录");

		// 行情报价
		Map<String, String> real_map = new HashMap<String, String>();
		real_map.put("en_prod_code", "600570.SS");//股票代码
		real_map.put("fields","open_px,preclose_px,high_px,low_px,business_amount,pe_rate,circulation_value,market_value,px_change,px_change_rate,trade_status");//字段集合
		HttpClientUtil.sendGet(HttpClientUtil.URL + "/quote/v1/real", real_map, HttpClientUtil.CHARSET, null,
				HttpClientUtil.BEARER + accesstoken.getAccess_token(), "行情报价");

	}

}
